package com.tianma315.admin.marshalling.controller;


import java.util.Arrays;
import java.util.List;

import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.marshalling.domain.MarshallingDO;
import com.tianma315.admin.marshalling.service.MarshallingService;

/**
 * 
 * <pre>
 * 班组
 * </pre>
 * <small> 2019-05-29 15:29:12 | Aron</small>
 */
@Controller
@RequestMapping("/marshalling/marshalling")
public class MarshallingController {
	@Autowired
	private MarshallingService marshallingService;
	
	@GetMapping()
	@RequiresPermissions("marshalling:marshalling:marshalling")
	String Marshalling(){
	    return "marshalling/marshalling/marshalling";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("marshalling:marshalling:marshalling")
	public Result<Page<MarshallingDO>> list(Integer pageNumber, Integer pageSize, MarshallingDO marshallingDTO){
		// 查询列表数据
        Page<MarshallingDO> page = marshallingService.getMarshallingDOPage(pageNumber,pageSize,marshallingDTO);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("marshalling:marshalling:add")
	String add(){
	    return "marshalling/marshalling/add";
	}

	@GetMapping("/edit/{marshallingId}")
	@RequiresPermissions("marshalling:marshalling:edit")
	String edit(@PathVariable("marshallingId") Integer marshallingId,Model model){
		MarshallingDO marshalling = marshallingService.selectById(marshallingId);
		model.addAttribute("marshalling", marshalling);
	    return "marshalling/marshalling/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("marshalling:marshalling:add")
	public Result<String> save( MarshallingDO marshalling){
		if(marshallingService.addMarshallingDO(marshalling)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("marshalling:marshalling:edit")
	public Result<String>  update( MarshallingDO marshalling){
		marshallingService.updateById(marshalling);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("marshalling:marshalling:remove")
	public Result<String>  remove( Integer marshallingId){
		if(marshallingService.deleteMarshallingDO(marshallingId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("marshalling:marshalling:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] marshallingIds){
		for (int i = 0; i < marshallingIds.length; i++) {
			marshallingService.deleteMarshallingDO(marshallingIds[i]);
		}
		return Result.ok();
	}

	/**
	 * 获取所有
	 */
	@GetMapping( "/getMarshallingList")
	@ResponseBody
	public Result<List<MarshallingDO>>  getMarshallingList(MarshallingDO marshallingDO){
		List<MarshallingDO> marshallingDOList = marshallingService.getMarshallingList(marshallingDO);
		return Result.ok(marshallingDOList);
	}
	
}
